#!/usr/bin/python
#coding:utf-8
import sys 
import getopt
import requests

opts, args = getopt.getopt(sys.argv[1:], "hs:f:", ["help", "server=", "file="])
#print("[*] Params: ", opts)
for opt_name,opt_val in opts:
    if opt_name in ('-h'):
        print ("[*] Usage: python3 http_client.py -s http://10.10.90.46:9000/IDCWebService/ -f <file>")
        sys.exit()
    if opt_name in ('-s', '--server'):
        ParamUrl = opt_val
    if opt_name in ('-f', '--filename'):
        ParamFileName = opt_val
        print ("[*] Param: -f ", ParamFileName)
        break

#for i in range(len(sys.argv)):
#    print ("第%d个参数是：%s" % (i,sys.argv[i]))
#print ("%d,%s" % (len(sys.argv), ParamFileName))

with open(ParamFileName, 'r') as fd:
    fileContext = fd.read()
headers = {'Content-Type': 'text/xml;charset=UTF-8'}
body = fileContext

req = requests.post(ParamUrl, data=body.encode("utf-8"), headers=headers)
# And done.
print(req.text) # displays the result body.
